|
1
|
|
|
/* |
|
2
|
|
|
* @copyright Copyright (c) 2016 Julius Härtl <[email protected]> |
|
3
|
|
|
* |
|
4
|
|
|
* @author Julius Härtl <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* @license GNU AGPL version 3 or any later version |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
11
|
|
|
* License, or (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
app.factory('BoardService', function(ApiService, $http, $q){ |
|
24
|
|
|
var BoardService = function($http, ep, $q) { |
|
25
|
|
|
ApiService.call(this, $http, ep, $q); |
|
26
|
|
|
}; |
|
27
|
|
|
BoardService.prototype = angular.copy(ApiService.prototype); |
|
28
|
|
|
|
|
29
|
|
|
BoardService.prototype.searchUsers = function(search) { |
|
30
|
|
|
var url = OC.generateUrl('/apps/deck/share/search/'+search); |
|
|
|
|
|
|
31
|
|
|
var deferred = $q.defer(); |
|
32
|
|
|
var self = this; |
|
33
|
|
|
$http.get(url).then(function (response) { |
|
34
|
|
|
|
|
35
|
|
|
self.sharees = []; |
|
36
|
|
|
// filter out everyone who is already in the share list |
|
37
|
|
|
angular.forEach(response.data, function(item) { |
|
38
|
|
|
var exists = false; |
|
39
|
|
|
angular.forEach(self.getCurrent().acl, function(acl) { |
|
40
|
|
|
if (acl.participant === item.participant) { |
|
41
|
|
|
exists = true; |
|
42
|
|
|
} |
|
43
|
|
|
}); |
|
44
|
|
|
if(!exists) { |
|
45
|
|
|
self.sharees.push(item); |
|
46
|
|
|
} |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
deferred.resolve(response.data); |
|
50
|
|
|
}, function (error) { |
|
|
|
|
|
|
51
|
|
|
deferred.reject('Error while update ' + self.endpoint); |
|
52
|
|
|
}); |
|
53
|
|
|
return deferred.promise; |
|
54
|
|
|
}; |
|
55
|
|
|
|
|
56
|
|
|
BoardService.prototype.addAcl = function(acl) { |
|
57
|
|
|
var board = this.getCurrent(); |
|
58
|
|
|
var deferred = $q.defer(); |
|
59
|
|
|
var self = this; |
|
|
|
|
|
|
60
|
|
|
var _acl = acl; |
|
61
|
|
|
$http.post(this.baseUrl + '/' + acl.boardId + '/acl', _acl).then(function (response) { |
|
62
|
|
|
if(!board.acl) { |
|
63
|
|
|
board.acl = {}; |
|
64
|
|
|
} |
|
65
|
|
|
board.acl[response.data.id] = response.data; |
|
66
|
|
|
deferred.resolve(response.data); |
|
67
|
|
|
}, function (error) { |
|
|
|
|
|
|
68
|
|
|
deferred.reject('Error creating ACL ' + _acl); |
|
69
|
|
|
}); |
|
70
|
|
|
acl = null; |
|
71
|
|
|
return deferred.promise; |
|
72
|
|
|
}; |
|
73
|
|
|
|
|
74
|
|
|
BoardService.prototype.deleteAcl = function(acl) { |
|
75
|
|
|
var board = this.getCurrent(); |
|
76
|
|
|
var deferred = $q.defer(); |
|
77
|
|
|
var self = this; |
|
|
|
|
|
|
78
|
|
|
$http.delete(this.baseUrl + '/' + acl.boardId + '/acl/' + acl.id).then(function (response) { |
|
79
|
|
|
delete board.acl[response.data.id]; |
|
80
|
|
|
deferred.resolve(response.data); |
|
81
|
|
|
}, function (error) { |
|
|
|
|
|
|
82
|
|
|
deferred.reject('Error deleting ACL ' + acl.id); |
|
83
|
|
|
}); |
|
84
|
|
|
acl = null; |
|
85
|
|
|
return deferred.promise; |
|
86
|
|
|
}; |
|
87
|
|
|
|
|
88
|
|
|
BoardService.prototype.updateAcl = function(acl) { |
|
89
|
|
|
var board = this.getCurrent(); |
|
90
|
|
|
var deferred = $q.defer(); |
|
91
|
|
|
var self = this; |
|
|
|
|
|
|
92
|
|
|
var _acl = acl; |
|
93
|
|
|
$http.put(this.baseUrl + '/' + acl.boardId + '/acl', _acl).then(function (response) { |
|
94
|
|
|
board.acl[_acl.id] = response.data; |
|
95
|
|
|
deferred.resolve(response.data); |
|
96
|
|
|
}, function (error) { |
|
|
|
|
|
|
97
|
|
|
deferred.reject('Error updating ACL ' + _acl); |
|
98
|
|
|
}); |
|
99
|
|
|
acl = null; |
|
100
|
|
|
return deferred.promise; |
|
101
|
|
|
}; |
|
102
|
|
|
|
|
103
|
|
|
BoardService.prototype.getPermissions = function() { |
|
104
|
|
|
var board = this.getCurrent(); |
|
105
|
|
|
var deferred = $q.defer(); |
|
106
|
|
|
$http.get(this.baseUrl + '/' + board.id + '/permissions').then(function (response) { |
|
107
|
|
|
board.permissions = response.data; |
|
108
|
|
|
console.log(board.permissions); |
|
|
|
|
|
|
109
|
|
|
deferred.resolve(response.data); |
|
110
|
|
|
}, function (error) { |
|
|
|
|
|
|
111
|
|
|
deferred.reject('Error fetching board permissions ' + board); |
|
112
|
|
|
}); |
|
113
|
|
|
}; |
|
114
|
|
|
|
|
115
|
|
|
BoardService.prototype.canRead = function() { |
|
116
|
|
|
if(!this.getCurrent() || !this.getCurrent().permissions) { |
|
117
|
|
|
return false; |
|
118
|
|
|
} |
|
119
|
|
|
return this.getCurrent().permissions['PERMISSION_READ']; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
BoardService.prototype.canEdit = function() { |
|
123
|
|
|
if(!this.getCurrent() || !this.getCurrent().permissions) { |
|
124
|
|
|
return false; |
|
125
|
|
|
} |
|
126
|
|
|
return this.getCurrent().permissions['PERMISSION_EDIT']; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
BoardService.prototype.canManage = function() { |
|
130
|
|
|
if(!this.getCurrent() || !this.getCurrent().permissions) { |
|
131
|
|
|
return false; |
|
132
|
|
|
} |
|
133
|
|
|
return this.getCurrent().permissions['PERMISSION_MANAGE']; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
BoardService.prototype.canShare = function() { |
|
137
|
|
|
if(!this.getCurrent() || !this.getCurrent().permissions) { |
|
138
|
|
|
return false; |
|
139
|
|
|
} |
|
140
|
|
|
return this.getCurrent().permissions['PERMISSION_SHARE']; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
service = new BoardService($http, 'boards', $q); |
|
|
|
|
|
|
144
|
|
|
return service; |
|
145
|
|
|
|
|
146
|
|
|
}); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.